package course11;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Hash2 {

    public static void main(String[] args) {

        Map hashMap = new HashMap<>();
        hashMap.put("name", "张三");
        hashMap.put("name2", "李四");
        hashMap.put("name3", "王五");

        System.out.println("hashMap的元素个数是：" + hashMap.size());

        //hashMap的遍历1
        /*Iterator iter = hashMap.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry name = (Map.Entry)iter.next();
            String nameKey = (String)name.getKey();
            String nameValue = (String)name.getValue();
            System.out.println(nameKey + "'s name is " + nameValue);
        }*/

        //遍历方法2 java8新增forEach

        hashMap.forEach((key, value) -> {
            System.out.println("key = " + key + ", value = " + value);
        });
    }
}
